<?php  include_once("authenticate.php");?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CP2010 MySql Exercise</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header">
  	<table width="100%" border="0px">
    <tr><td rowspan="2"><h1>Sign Book</h1></td>
    <td style="color:#039; font-weight: bold; text-align:right;"><?php	echo 'User: ' . $_SESSION['userEmail']?></td></tr>
    <tr><td style="color:#039; font-weight: bold; text-align:right;"><a href="index.php">Open Address Book</a></td><tr>
    </table>
  <!-- end #header --></div>
  <div id="mainContent">
  	<p>
    <!-- upon the page launch, retrieve all records from table colleague and display -->
    <table border="1" cellpadding="10px" cellspacing="0">
    <tr>
    <th>No.</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Sign In</th>
    <th>Sign Out</th>                
    </tr>
    <?php
		$myDB = new db();
		
		// retrieve first and last name
		 $firstName ="";
		 $lastName = ""; 
		$result = $myDB->sendSQLStatement("SELECT * FROM colleague WHERE email='" . $_SESSION['userEmail'] . "'");
		while ($row = mysql_fetch_assoc($result) ) {
			$firstName = $row['firstname'];
			$lastName = $row['lastname'];
			break;
		}
		mysql_free_result($result);	
		
 		$result = $myDB->sendSQLStatement("SELECT * FROM signbook");
		//loop through all table rows
		while ($row = mysql_fetch_assoc($result) ) {
			echo "<tr>";
			echo "<td>" . $row['id'] . "</td>";				
			echo "<td>" . $firstName . "</td>";
			echo "<td>" . $lastName . "</td>";
			echo "<td>" . $row['signin'] . "</td>";
			echo "<td>" . $row['signout'] . "</td>";			
			echo "</tr>";										
		}
		// free result memory
		mysql_free_result($result);	
    ?>
    </table></p>
	<!-- end #mainContent --></div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p>CP2010 MySql Exercise</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>